#include "include.hpp"
int main()
{
    key_t key = ftok(PATH, PRID);
    int shmid = shmget(key, SIZE, 0);
    cout << shmid << endl;
    char *address = reinterpret_cast<char *>(shmat(shmid, nullptr, 0));
    if (address == reinterpret_cast<char *>(-1))
    {
        perror("shmat");
        exit(-1);
    }
    // 临界区
    while (true)
    {
        wait();
        if (strcmp(address + 1, "quit\n") == 0)
        {
            address[0] = 'y';
            break;
        }
        else
        {
            printf("%s", address + 1);
            memset(address, 0, SIZE);
        }
    }
    // 删除管道文件
    unlink(FIFE_PATH);
    cout << "管道文件删除成功" << endl;
    // 去除挂接
    int ret = shmdt(address);
    assert(ret != -1);
    cout << "去除挂接成功" << endl;
    return 0;
}